const app = getApp()
const db = wx.cloud.database()
Page({
  data: {
    num: 0
  },
  onLoad(options) {
    wx.showLoading({
      title: '数据通信中',
      mask: true
    })
    db.collection('gongzhonghao').get().then(res => {
      const info = res.data
      this.setData({
        info
      })
      this.Set_navbar()
    })
    wx.hideLoading()
  },
  Set_navbar() {
    const {
      top,
      height
    } = wx.getMenuButtonBoundingClientRect();
    const {
      statusBarHeight
    } = wx.getSystemInfoSync();
    const navbarHeight = (top - statusBarHeight) * 2 + height + statusBarHeight
    this.setData({
      navbarHeight: navbarHeight
    })
  },
  GoBack() {
    wx.navigateBack({
      delta: 1
    })
  },
  WorkShop(e) {
    const id = parseInt(e.currentTarget.dataset.id)
    const url = this.data.info[id].url
    wx.navigateTo({
      url: '/pages/official-account/openurl/openurl?url='+url,
    })
  },
  // 监听页面
  onPageScroll(e) {
    var user = e.scrollTop
    if (user <= 100) {
      this.setData({
        num: 0,
      })
    } else if (100 < user < 300) {
      this.setData({
        num: user / 300,
      })
    } else if (user > 300) {
      this.setData({
        num: 0.5,
      })
    }
  },
})